-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(audio): Normalize 'x-wav' audio format to 'wav' #9017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(audio): Normalize 'x-wav' audio format to 'wav' #9017
Conversation
|
Thanks @akshatvishu, can you add a unit test? |
|
@TomeHirata Added the unit-test and also I slightly changed the logic and used the removeprefix() instead of the replace() to safely remove only the prefix from audio format strings, preventing unintended replacements if |
TomeHirata
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Closes #8996
Description:
The
dspy.Audio.from_file(andfrom_url) method relies on Python'smimetypes.guess_type()to determine the audio format. On some operating systems, this function can return non-standard MIME types, such asaudio/x-wavfor.wavfiles.These non-standard format strings, often prefixed with x- (like
x-wavorx-m4a), are then passed to the LLM API (e.g., OpenAI). This can cause a400 BadRequestError, as the API typically only accepts compliant formats (e.g., wav, m4a).This patch adds a check to
from_file,from_url, and the data URI branch ofencode_audioto normalize these formats by removing any x- prefix, ensuring an API-compliant format is always sent.